package com.heima.mapper;

import com.github.pagehelper.Page;
import com.heima.dto.ActivitiesPageDto;
import com.heima.pojo.Activities;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ActivitiesMapper {

    /**
     * 新增活动
     * @param activities
     */
    @Insert("insert into tb_active(channel,code, name, info, type, update_time, create_time, begin_time, end_time, discount, vouchers)\n" +
            "values(#{channel},#{code},#{name},#{info},#{type},#{updateTime},#{createTime},#{beginTime},#{endTime},#{discount},#{vouchers})")
    void insertActivity(Activities activities);

    /**
     * 活动查询
     * @param activitiesPageDto
     * @return
     */
    Page<Activities> queryActivitiesList(ActivitiesPageDto activitiesPageDto);

    /**
     * 修改界面信息回显
     * @param id
     * @return
     */
    @Select("select ta.* from tb_active ta left join tb_dictionary td on ta.type = td.dict_value and td.dict_type ='activity_status' where ta.id = #{id}")
    Activities getActivitiesInfo(Integer id);

    /**
     * 修改活动
     * @param activities
     */
    void updateActivities(Activities activities);

    /**
     * 删除活动
     * @param id
     */
    @Delete("delete from tb_active where id = #{id}")
    void deleteActivities(Integer id);

    /**
     * 根据渠道来源查询所有活动
     * @param channel
     * @return
     */
    @Select("select * from tb_active where channel = #{channel}")
    List<Activities> getActivityByChannel(Integer channel);
}
